var express = require('express');
var router = express.Router();

model = require('../models/model')
router.get('/', function(req, res, next) {
  let response = res;
  let input = new RegExp(req.query.input);
    model.mapListLessNumbers.find({
    "character": new RegExp(input)
  }, (err, result, res) => {
    // console.log(result);//id和特征
    var data = [];
    var datas = [];
    for (var i in result) {
      // console.log(result[i].idItem);
      model.idDatas.findOne({
        "_id": result[i].idItem
      }, function(err, doc) {
        // console.log(doc);
        id_data={
          id:doc._id,
          data:doc.datas
        }
        data.push(id_data);
        var title = doc.titlesId;
        datas = {
          list: data,
          title,
        };
      });
    }
    model.idDatas.findOne({}, function() {
      console.log(datas);
      response.render('users',{docs:datas});
    })
  })
});
module.exports = router;
